﻿
#include "data.h"
#include "conf_mgr.h"

//////////////////////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////////////////////

void loadGlobalData() {
    g_appData.childLocked = g_objConf->getChildLockFlag();
    g_appData.isMute      = g_objConf->getMuteFlag();
    g_appData.volumeNum   = g_objConf->getVolume();
}

void setScreenLight(int light) {
    // /sys/class/pwm/pwmchip0/pwm0/duty_cycle 数值就为pwm占空比，范围[1-99]
    char path_duty_cycle[] = "/sys/class/pwm/pwmchip0/pwm0/duty_cycle";
    if (access(path_duty_cycle, F_OK)) { return; }

    int pwm = (MAX_SCREEN_LIGHT - light) * 99 / MAX_SCREEN_LIGHT;
    if (pwm > 99) {
        pwm = 44; // 暗
    } else if (pwm < 1) {
        pwm = 1; // 亮
    }

    char shell[128];
    snprintf(shell, sizeof(shell), "echo %d > %s", pwm, path_duty_cycle);
    system(shell);
}
